//
//  OldPhotoNet.m

#import "OldPhotoNet.h"
@interface OldPhotoNet()
@property (strong, nonatomic) AFHTTPSessionManager *oldPhotoManger;
@end
@implementation OldPhotoNet
static OldPhotoNet *defaultManger = nil;
 + (OldPhotoNet*)defaultManger{
     static dispatch_once_t token;
     dispatch_once(&token, ^{
         if(defaultManger == nil){
             defaultManger = [[OldPhotoNet alloc] init];
             defaultManger.oldPhotoManger = [AFHTTPSessionManager manager];
             defaultManger.oldPhotoManger.requestSerializer = [AFHTTPRequestSerializer serializer];
             defaultManger.oldPhotoManger.responseSerializer = [AFHTTPResponseSerializer serializer];
             defaultManger.oldPhotoManger.requestSerializer.timeoutInterval = 12.0;
         }
     });
     return defaultManger;
}
- (void)oldPhotoNetPost:(NSString *)url withParaDic:(NSDictionary *)paramDic withSuccess:(void(^)(id data))successBlack withFail:(void(^)(void))failBlack{
    [self.oldPhotoManger POST:url parameters:paramDic headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if(responseObject){
            NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
            if([jsonDict[@"code"] intValue] == 200){
                successBlack(jsonDict);
            }else{
                [SVProgressHUD showInfoWithStatus:jsonDict[@"msg"]];
                failBlack();
            }
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failBlack();
    }];
}
@end
